
#include "Unit.h"

vector<Unit*> Unit::units;
HTEXTURE Unit::texture;

//
// Constructor
//

Unit::Unit(int x0, int y0, int x1, int y1)
{
	quad.blend = BLEND_DEFAULT;
	quad.tex = texture;

	quad.v[0].tx = float(x0) / 143.0f;
	quad.v[1].tx = float(x1) / 143.0f;
	quad.v[2].tx = float(x1) / 143.0f;
	quad.v[3].tx = float(x0) / 143.0f;

	quad.v[0].ty = float(y0) / 654.0f;
	quad.v[1].ty = float(y0) / 654.0f;
	quad.v[2].ty = float(y1) / 654.0f;
	quad.v[3].ty = float(y1) / 654.0f;

	for(int i = 0; i < 4; i++)
	{
		quad.v[i].col = 0xFFFFFFFF;
		quad.v[i].z = 0.5f;
	}

	width  = 2 * float(x1-x0) / 143.0f;
	height = 2 * float(y1-y0) / 143.0f;

	units.push_back(this);
}

//
// Render
//

void Unit::Render(float x, float y, float imageSize)
{
	quad.v[0].x = x;
	quad.v[1].x = x + width*imageSize;
	quad.v[2].x = x + width*imageSize;
	quad.v[3].x = x; 

	quad.v[0].y = y;
	quad.v[1].y = y;
	quad.v[2].y = y + height*imageSize;
	quad.v[3].y = y + height*imageSize;

	hge->Gfx_RenderQuad(&quad);
}
